package org.example.petitionplatformsystem.controller;

import org.example.petitionplatformsystem.Response;
import org.example.petitionplatformsystem.dao.model.PetitionEvents;
import org.example.petitionplatformsystem.service.AuthPetitionService;
import org.example.petitionplatformsystem.service.EmotionAnalysisService;
import org.example.petitionplatformsystem.service.PetitionEventsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/data")
public class BigdataAnalysisController {
    @Autowired
    private PetitionEventsService petitionEventsService;
    @Autowired
    private AuthPetitionService authPetitionService;
    @Autowired
    private EmotionAnalysisService emotionAnalysisService;
    @GetMapping("/getKeywordsCounts")
    public Response<List<Map<String, Object>>> generateWordCloud() {
        List<Map<String, Object>> wordCloudResult = petitionEventsService.getKeywordsCounts();
        return Response.newSuccessResponse(wordCloudResult);
    }
    @GetMapping("/getTitleKeysCounts")
    public Response<List<Map<String, Object>>> generateTitleKeysCounts() {
        List<Map<String, Object>> titleKeysCounts = petitionEventsService.getTitleKeywordsCounts();
        return Response.newSuccessResponse(titleKeysCounts);
    }
    @GetMapping("getPetitionInfoData")
    public Response<Map<String, Object>> getPetitionInfoData() {

        Map<String, Object> petitionInfoData = petitionEventsService.getPetitionInfodata();
        return Response.newSuccessResponse(petitionInfoData);
    }
    @GetMapping("/getDailyPetitionCounts")
    public Response<List<Map<String, Object>>> getDailyPetitionCounts() {

        List<Map<String, Object>> dailyPetitionCounts = petitionEventsService.getPetitionCountsByDay();
        return Response.newSuccessResponse(dailyPetitionCounts);
    }
    @GetMapping("/getPetitionCountByStatus/{Data}")
    public Response<Map<String, Object>> getPetitionCountByStatus(@PathVariable String Data) {

        Map<String, Object> petitionCountByStatus = petitionEventsService.getPetitionCountsByDayAndStatus(Data);
        return Response.newSuccessResponse(petitionCountByStatus);
    }
    @GetMapping("/getPetitionCountByAddress")
    public Response<Map<String, Object>> getPetitionCountByAddress() {

        Map<String, Object> petitionCountByAddress = authPetitionService.getPetitionCountsByAddress();
        return Response.newSuccessResponse(petitionCountByAddress);
    }
    @GetMapping("/getWeekPetitionCounts")
    public Response<List<Map<String, Object>>> getWeekPetitionCounts() {

        List<Map<String, Object>> weekAndYearPetitionCounts = petitionEventsService.getPetitionCountsByWeek();
        return Response.newSuccessResponse(weekAndYearPetitionCounts);
    }

    @GetMapping("/getMonthPetitionCounts")
    public Response<List<Map<String, Object>>> getMonthPetitionCounts() {

        List<Map<String, Object>> weekAndYearPetitionCounts = petitionEventsService.getPetitionCountsByMonth();
        return Response.newSuccessResponse(weekAndYearPetitionCounts);
    }
    @GetMapping("/getAllPetition")
    public Response<List<PetitionEvents>> getTitleEmotionAnalysis() {

        return Response.newSuccessResponse(petitionEventsService.getAllPetitionEvents());
    }
}
